package com.zhouyer.study.mvcframework.pojo;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * 主要用于封装handler方法相关的信息
 *
 * @author zhouyao
 */
public class Handler {
    /**
     * 表示哪个controller，即handler方法所在的对象
     */
    private Object controller;

    /**
     * 表示具体的url映射的具体method
     */
    private Method method;

    /**
     * Spring中url支持正则
     */
    private Pattern pattern;

    /**
     * 记录有权限的用户名称
     */
    private List<String> userPermissions;

    /**
     * 存储参数的顺序，为了进行参数绑定，key为参数名，value代表是第几个参数，如<name,2>
     */
    private Map<String, Integer> paramIndexMapping;

    public Handler(Object controller, Method method, Pattern pattern) {
        this.controller = controller;
        this.method = method;
        this.pattern = pattern;
        this.paramIndexMapping = new HashMap<>(16);
    }

    public Object getController() {
        return controller;
    }

    public void setController(Object controller) {
        this.controller = controller;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public Pattern getPattern() {
        return pattern;
    }

    public void setPattern(Pattern pattern) {
        this.pattern = pattern;
    }

    public Map<String, Integer> getParamIndexMapping() {
        return paramIndexMapping;
    }

    public void setParamIndexMapping(Map<String, Integer> paramIndexMapping) {
        this.paramIndexMapping = paramIndexMapping;
    }

    public List<String> getUserPermissions() {
        return userPermissions;
    }

    public void setUserPermissions(List<String> userPermissions) {
        this.userPermissions = userPermissions;
    }
}
